package com.zhou.springcloud.cousumer.service.impl;

import com.zhou.springcloud.cousumer.service.IProdiverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhouyongjun
 * @Description:
 * @date 2021/3/23 8:43
 */
@Service
public class ProdiverServiceImpl implements IProdiverService {
    @Autowired
    DiscoveryClient discoveryClient;
    @Override
    public List<ServiceInstance> getServiceInstances(String serviceId) {
        return discoveryClient.getInstances(serviceId);
    }

    @Override
    public ServiceInstance getServiceInstance(String serviceId) {
        List<ServiceInstance>  list = getServiceInstances(serviceId);
        return list.isEmpty() ? null : list.get(0);
    }
}
